<?php

namespace tmcore\services\wechat;

use tmcore\services\ConfigService;

/**
 * 微信配置类
 */
class WxConfigService
{
    /**
     * 获取微信小程序配置
     * @return array
     */
    public static function getMnpConfig()
    {
        $config = (new ConfigService)->getConfig('wx_ap_channel', 'sys');
        return [
            'app_id' => $config['app_id'] ?? '',
            'secret' => $config['app_secret'] ?? '',
            'response_type' => 'array',
            'log' => [
                'level' => 'debug',
                'file'  => app()->getRootPath() . 'runtime/wechat/' . date('Ym') . '/' . date('d') . '.log'
            ],
        ];
    }

    /**
     * 获取微信公众号配置
     * @return array
     */
    public static function getOaConfig()
    {
        $config = (new ConfigService)->getConfig('wx_oa_channel', 'sys');
        return [
            'app_id' => $config['app_id'] ?? '',
            'secret' => $config['app_secret'] ?? '',
            'token' => $config['token'] ?? '',
            'aes_key' => (isset($config['encryption_type']) && $config['encryption_type'] == 1)?'':($config['encoding_aes_key'] ?? ''),
            'response_type' => 'array',
            'log' => [
                'level' => 'debug',
                'file' => app()->getRootPath() . 'runtime/wechat/' . date('Ym') . '/' . date('d') . '.log'
            ]
        ];
    }

    /**
     * 获取微信开放平台配置
     * @return array
     */
    public static function getOpConfig()
    {
        $config = (new ConfigService)->getConfig('wx_op_channel', 'sys');
        return array(
            'app_id' => $config['app_id'] ?? '',
            'secret' => $config['app_secret'] ?? '',
            'response_type' => 'array',
            'log' => [
                'level' => 'debug',
                'file'  => app()->getRootPath() . 'runtime/wechat/' . date('Ym') . '/' . date('d') . '.log'
            ]
        );
    }
}